import java.awt.Point;
import java.util.ArrayList;
import java.util.HashSet;

public class Pattern {
	ArrayList<Point> pattBoxes;
	ArrayList<Point> walls;
	int nbGoal;

	public Pattern(ArrayList<Point> pattBoxes, ArrayList<Point> walls,
			int nbGoal) {
		this.pattBoxes = pattBoxes;
		this.walls = walls;
		this.nbGoal = nbGoal;
	}

	public boolean isPatternDeadlock(HashSet<Point> boxes) {
		Point tempPoint = new Point();
		for (Point box : boxes) {
			boolean noMatch = false;
			int goal = 0;
			for (Point pattBox : pattBoxes) {
				tempPoint.x = box.x + pattBox.x;
				tempPoint.y = box.y + pattBox.y;
				if (!boxes.contains(tempPoint)) {
					noMatch = true;
					break;
				}
				if (Main.goals.contains(tempPoint)) {
					goal++;
				}
			}
			if (!noMatch) {
				for (Point wall : walls) {
					tempPoint.x = box.x + wall.x;
					tempPoint.y = box.y + wall.y;
					if (Main.map.length > tempPoint.x && tempPoint.x >= 0
							&& Main.map[tempPoint.x].length > tempPoint.y
							&& tempPoint.y >= 0) {
						if (Main.map[tempPoint.x][tempPoint.y] != '#') {
							noMatch = true;
							break;
						}
					} else {
						noMatch = true;
						break;
					}
				}
			}
			if (!noMatch && nbGoal > goal) {
				return true;
			}
		}

		return false;
	}

}
